package com.hnx.admin.aurora.system.controller;

import com.hnx.admin.aurora.annotation.Log;
import com.hnx.admin.aurora.enums.BusinessType;
import com.hnx.admin.aurora.system.domain.param.dict.form.DictDataForm;
import com.hnx.admin.aurora.system.domain.param.dict.query.DictDataQuery;
import com.hnx.admin.aurora.system.service.SysDictDataService;
import com.hnx.admin.aurora.utils.UUIDUtil;
import com.hnx.admin.aurora.web.json.ResultJson;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/*
创建人： 倔强的头发
创建时间：2025/6/18
功能描述:

*/
@RestController
@RequestMapping("/system/dict/data")
@RequiredArgsConstructor
public class SysDictDataController {
//    private final SysDictTypeService dictTypeService;
    private final SysDictDataService sysDictDataService;

    /**
     * 根据字典类型查询字典数据信息
     */
    @GetMapping(value = "/type/{dictType}")
    public ResultJson dictType(@PathVariable String dictType) {
        return sysDictDataService.selectDictDataByType(dictType);
    }
    @PreAuthorize("@auth.hasPermi('system:dict:list')")
    @GetMapping("/list")
    public ResultJson list(DictDataQuery dictData)
    {
        return sysDictDataService.selectDictDataList(dictData);
    }
    /**
     * 新增字典类型
     */
    @PreAuthorize("@auth.hasPermi('system:dict:add')")
    @Log(title = "字典数据", businessType = BusinessType.INSERT)
    @PostMapping
    public ResultJson add(@Validated @RequestBody DictDataForm dict)
    {
        dict.setDictCode(UUIDUtil.getUUID());
        return sysDictDataService.insertDictData(dict);
    }
    /**
     * 查询字典数据详细
     */
    @PreAuthorize("@auth.hasPermi('system:dict:query')")
    @GetMapping(value = "/{dictCode}")
    public ResultJson getInfo(@PathVariable String dictCode)
    {
        return sysDictDataService.selectDictDataById(dictCode);
    }
    /**
     * 删除字典类型
     */
    @PreAuthorize("@auth.hasPermi('system:dict:remove')")
    @Log(title = "字典类型", businessType = BusinessType.DELETE)
    @DeleteMapping("/{dictCodes}")
    public ResultJson remove(@PathVariable String[] dictCodes)
    {
        return sysDictDataService.deleteDictDataByIds(dictCodes);
    }
    /**
     * 修改保存字典类型
     */
    @PreAuthorize("@auth.hasPermi('system:dict:edit')")
    @Log(title = "字典数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public ResultJson edit(@Validated @RequestBody DictDataForm dict)
    {
        return sysDictDataService.updateDictData(dict);
    }
}
